package com.sinping.qh.query.lab;

import com.sinping.qh.query.base.Operator;
import com.sinping.qh.query.base.QueryParams;
import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jiahuaiqing
 * @create 2018/6/1
 */
@Data
public class LaboratoryQuery implements QueryParams, Serializable {
    private static final long serialVersionUID = -7927130362370790109L;
    private static Map<String, String> alisMap = new HashMap<>();
    private static Map<String, Operator> operatorMap = new HashMap<>();

    private String labName;

    private String unitId;

    private String buildingId;
    private String status;
    /**
     * 用于查询实验室分页
     */
    private List<String> labIDList;
    /**
     * 用于查询实验室分页
     */
    private List<String> unitIDList;
    /**
     * 用于查询实验室分页
     */
    private List<String> buildingIDList;

    static {
        alisMap.put("labIDList", "_id");
        alisMap.put("labName", "lab_name");
        alisMap.put("unitId", "unit_id");
        alisMap.put("unitIDList", "unit_id");
        alisMap.put("buildingId", "building_id");
        alisMap.put("buildingIDList", "building_id");
        alisMap.put("status", "status");

        operatorMap.put("labName", Operator.regex);
        operatorMap.put("unitId", Operator.eq);
        operatorMap.put("status", Operator.eq);
        operatorMap.put("buildingId", Operator.eq);
        operatorMap.put("labIDList", Operator.in);
        operatorMap.put("unitIDList", Operator.in);
        operatorMap.put("buildingIDList", Operator.in);
    }

    @Override
    public String getAlias(String fieldName) {
        return alisMap.getOrDefault(fieldName, fieldName);
    }

    @Override
    public Operator getOperators(String fieldName) {
        return operatorMap.getOrDefault(fieldName, Operator.eq);
    }
}
